package com.hsgene.user.dto.register;

import com.hsgene.common.util.basic.SimpleRegexUtils;
import com.hsgene.common.util.exception.ErrorCode;
import com.hsgene.common.util.validation.FieldChecker;
import com.hsgene.user.dto.address.ConsignAddressDto;
import com.hsgene.user.exception.UserErrorCode;

import java.io.Serializable;

/**
 * 员工注册信息
 *
 * @author wangbing
 * @version 1.0, 2018/7/12
 */
public class EmployeeRegisterDto implements Serializable {

    private static final long serialVersionUID = 7728705145639102951L;
    /**
     * 供应商id（0表示平台注册用户）
     */
    private Long supplierId = 0L;

    /**
     * 账号
     */
    private String userName;

    /**
     * 密码
     */
    private String password;

    /**
     * 昵称、用户名
     */
    private String nickName;

    /**
     * 角色类型
     */
    private String roleType;

    /**
     * 收货地址（当 supplierId = 0时此字段有意义）
     */
    private ConsignAddressDto consignAddress;

    /**
     * 注册IP
     */
    private String registerIp;

    public ErrorCode check() {
        FieldChecker.checkEmpty(supplierId, "supplierId");
        FieldChecker.checkEmpty(password, "密码");
        FieldChecker.checkEmpty(roleType, "角色类型");
        FieldChecker.checkMaxLength(nickName, 10, "用户名");
        FieldChecker.checkEmpty(userName, "手机号");
        // 普通管理员需要用电话号码作为账号
        if (!SimpleRegexUtils.isMobile(userName)) {
            return UserErrorCode.USER_PHONE_NOT_FORMAT;
        }
        if (supplierId == 0) {
            consignAddress.simpleCheck();
        }
        return null;
    }

    public Long getSupplierId() {
        return supplierId;
    }

    public void setSupplierId(Long supplierId) {
        this.supplierId = supplierId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getRoleType() {
        return roleType;
    }

    public void setRoleType(String roleType) {
        this.roleType = roleType;
    }

    public ConsignAddressDto getConsignAddress() {
        return consignAddress;
    }

    public void setConsignAddress(ConsignAddressDto consignAddress) {
        this.consignAddress = consignAddress;
    }

    public String getRegisterIp() {
        return registerIp;
    }

    public void setRegisterIp(String registerIp) {
        this.registerIp = registerIp;
    }
}
